package com.bcx.crm.java.httpServlet.ServletContextTest;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by ys on 2018/1/22.
 */

/**
 * 添加servletContext属性
 */
@WebServlet(urlPatterns = "/servletContext1")
public class ServletContext1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = resp.getWriter();
        ServletContext servletContext = this.getServletContext();
        servletContext.setAttribute("myInfo","woshishanghai");
        writer.println("给ServletContext添加了一个属性myInf<br/>");
        HttpSession session = req.getSession(true);
        session.setAttribute("test","中国人");
        session.setMaxInactiveInterval(60*3);
        writer.println("向session中添加一个test属性,他的值是中国人");
    }
}
